package com.macro.mall.controller;

import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.model.BannerInfo;
import com.macro.mall.service.BannerInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * BannerInfo的路由接口服务
 * 
 * @author 
 *
 */
@Slf4j
@RestController
@RequestMapping("BannerInfoController")
@Api(tags = "banner", description = "banner 管理")
public class BannerInfoController {

	/** BannerInfoService服务 */
	@Autowired
	private BannerInfoService bannerInfoService;
	
	/**
	 * 查询所有BannerInfo数据的方法
	 * @param
	 * @return
	 */
    @ResponseBody
    @ApiOperation("查询banner")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public CommonResult find(@ApiParam(value = "通过发布时间倒叙: create_time desc 通过数据排序字段正序 sort asc ") @RequestParam(value = "orderBy", required = false) String orderBy,
                             @ApiParam(value = "01-课程 02-服务 03-新闻 04-广告 05-居委会") @RequestParam(value = "sourceType", required = false) String sourceType,
                             @ApiParam(value = "01-首页 02-学习首页") @RequestParam(value = "position", required = false) String position,
                             @ApiParam(value = "1-APP 2-小程序 3-公众号") @RequestParam(value = "channel", required = false) String channel) {
		return CommonResult.success(CommonPage.restPage(bannerInfoService.find(channel, orderBy, sourceType, position)));
	}
	
	/**
	 * 通过id查询BannerInfo数据的方法
	 * @param id
	 * @return
	 */
    @ApiOperation("根据id查询")
	@GetMapping(value = "/getById", produces = {"application/json;charset=UTF-8"})
	public CommonResult findOne(@RequestParam(name="id") Integer id) {
		return CommonResult.success(bannerInfoService.findOne(id));
	}
	
	/**
	 * 插入BannerInfo属性不为空的数据方法
	 * @param value
	 * @return
	 */
    @ApiOperation("保存")
	@PostMapping(value = "/save", produces = {"application/json;charset=UTF-8"})
	public CommonResult save(@RequestBody BannerInfo value) {
        bannerInfoService.saveNotNull(value);
		return CommonResult.success(null);
	}
	
	/**
	 * 更新BannerInfo属性不为空的数据方法
	 * @param value
	 * @return
	 */
    @ApiOperation("修改")
	@PostMapping(value = "/update", produces = {"application/json;charset=UTF-8"})
	public CommonResult update(@RequestBody BannerInfo value) {
        bannerInfoService.updateNotNullById(value);
		return CommonResult.success(null);
	}

	/**
	 * 通过id删除BannerInfo数据方法
	 * @param id
	 * @return
	 */
    @ApiOperation("删除")
	@GetMapping(value = "/delete", produces = {"application/json;charset=UTF-8"})
	public CommonResult delete(@RequestParam(name="id") Integer id) {
        bannerInfoService.deleteById(id);
        return CommonResult.success(null);
	}
}
